package com.heima.controller;

import com.heima.dto.LoginDto;
import com.heima.result.Result;
import com.heima.service.IUsersService;
import com.heima.vo.LoginTokenVo;
import com.heima.vo.LoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private IUsersService service;

    @GetMapping("openId")
    public Result getOpenId(@RequestParam String code) {
        LoginVo openId = service.getOpenId(code);
        return Result.success(openId);
    }

    @PostMapping("register")
    public Result redister(@RequestBody LoginDto dto) {
        LoginTokenVo register = service.register(dto);
        return Result.success(register);
    }
}
